<h1>Counter</h1>
<p>Current count: @currentCount</p>
<p><button id="counter" @onclick="OnClickHandler">Click me</button></p>

<label>
	<input type="checkbox" @bind="handleClicks" />
	Toggle click handler registration
</label>

@if (handleClicks)
{
	<p id="listening-message">Listening</p>
}

@code {
	private Action OnClickHandler
	{
		get
		{
			if (handleClicks)
				return IncrementCount;
			else
				return default!;
		}
	}

	int currentCount = 0;
	bool handleClicks = true;

	void IncrementCount()
	{
		currentCount++;
	}

	public void Reset()
	{
		currentCount = 0;
		StateHasChanged();
	}
}
